home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / AppWannabe / DoEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-12  |  5.2 KB  |  211 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        DoEvent.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.protos.h"        /* Get the prototypes for application.            */
  27.  
  28. #ifndef __CTLHANDLER__
  29. #include "CtlHandler.h"
  30. #endif
  31.  
  32. #ifndef __DESK__
  33. #include <Desk.h>
  34. #endif
  35.  
  36. #ifndef __DISKINIT__
  37. #include <DiskInit.h>
  38. #endif
  39.  
  40. #ifndef __ERRORS__
  41. #include <Errors.h>
  42. #endif
  43.  
  44. #ifndef __MENUS__
  45. #include <Menus.h>
  46. #endif
  47.  
  48. #ifndef __TEXTEDITCONTROL__
  49. #include "TextEditControl.h"
  50. #endif
  51.  
  52. #ifndef __TEXTSERVICES__
  53. #include "TextServices.h"
  54. #endif
  55.  
  56. #ifndef __TOOLUTILS__
  57. #include <ToolUtils.h>
  58. #endif
  59.  
  60. #ifndef __UTILITIES__
  61. #include "Utilities.h"
  62. #endif
  63.  
  64.  
  65.  
  66. /*****************************************************************************/
  67.  
  68.  
  69.  
  70. extern Cursor    *gCursorPtr;    /* See the file Window.c for comments about this global. */
  71.  
  72.  
  73.  
  74. /*****************************************************************************/
  75. /*****************************************************************************/
  76.  
  77.  
  78.  
  79. /* Do the right thing for an event.  Determine what kind of event it is, and
  80. ** call the appropriate routines. */
  81.  
  82. #pragma segment Main
  83. void    DoEvent(EventRecord *event)
  84. {
  85.     Point        pt;
  86.     OSErr        err;
  87.  
  88.     switch(event->what) {
  89.  
  90.         case nullEvent:
  91.             DoIdleTasks(event);
  92.             break;
  93.  
  94.         case mouseDown:
  95.             DoMouseDown(event);
  96.             break;
  97.  
  98.         case autoKey:
  99.         case keyDown:                    /* Check for menukey equivalents. */
  100.             DoKeyDown(event);
  101.             break;
  102.  
  103.         case activateEvt:
  104.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  105.             DoActivate((WindowPtr)event->message);
  106.             if (TSMTEAvailable()) TSMEvent(event);
  107.             break;
  108.  
  109.         case updateEvt:
  110.             DoUpdate((WindowPtr)event->message);
  111.             break;
  112.  
  113.         case kHighLevelEvent:
  114.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  115.             DoHighLevelEvent(event);
  116.             break;
  117.  
  118.         case osEvt:
  119.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  120.             switch ((event->message >> 24) & 0xFF) {
  121.                     /* Must logical and with 0xFF to get only low byte. */
  122.                     /* High byte of message. */
  123.  
  124.                 case mouseMovedMessage:
  125.                     DoIdleTasks(event);
  126.                     break;
  127.  
  128.                 case suspendResumeMessage:
  129.                         /* Suspend/resume is also an activate/deactivate. */
  130.                     gInBackground = !((event->message) & resumeFlag);
  131.                     CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
  132.                     DoActivate(FrontWindow());
  133.                     HiliteWindows();
  134.                     break;
  135.             }
  136.             break;
  137.  
  138.         case diskEvt:
  139.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  140.             if (HiWord(event->message) != noErr) {
  141.                 SetPt(&pt, kDILeft, kDITop);
  142.                 err = DIBadMount(pt, event->message);
  143.             }
  144.             break;        /* It is not a bad idea to at least call DIBadMount
  145.                         ** in response to a diskEvt, so that the user can
  146.                         ** format a floppy. */
  147.     }
  148.  
  149.     DoCursor();
  150.     DoAdjustMenus();
  151. }
  152.  
  153.  
  154.  
  155. /*****************************************************************************/
  156.  
  157.  
  158.  
  159. /* •• Called by DTS.Lib..framework. •• */
  160.  
  161. /* This is called when a window is activated or deactivated. */
  162.  
  163. #pragma segment Main
  164. void    DoActivate(WindowPtr window)
  165. {
  166.     RgnHandle    rgn, oldClip;
  167.     Point        pt;
  168.  
  169.     NotifyCancel();
  170.  
  171.     if (IsAppWindow(window)) {
  172.  
  173.         SetPort(window);
  174.         DoCtlActivate(window);
  175.         DoDrawFrame(window, true);            /* Redraw frame for new activate state. */
  176.  
  177.         CopyRgn(((WindowPeek)window)->contRgn, rgn = NewRgn());
  178.         DiffRgn(rgn, ((WindowPeek)window)->updateRgn, rgn);
  179.             /* Don't draw any part that's already destined to draw due to an update event.
  180.             ** This prevents part of an exposed window from drawing twice, and thus avoids
  181.             ** flickering. */
  182.  
  183.         BeginContent(window);
  184.  
  185.         pt.h = pt.v = 0;
  186.         GlobalToLocal(&pt);
  187.         OffsetRgn(rgn, pt.h, pt.v);
  188.             /* This offset may seem wrong, since the origin may not be 0,0.  It is actually correct,
  189.             ** since at the time of the GlobalToLocal, the port's origin was set to the content origin.
  190.             ** A clearer way to look at this is in two steps:
  191.             ** 1) With the port's origin at 0,0, do a GlobalToLocal on 0,0, and then offset the new clip
  192.             **    by that amount.
  193.             ** 2) Once the port's origin is set correctly, the new clip needs to be offset again, based
  194.             **    on the origin value.  (The clipRgn travels with the origin, unlike the visRgn.)
  195.             ** The above is what automatically happens when you do the GlobalToLocal of 0,0 on the
  196.             ** correct origin.  Offsets are additive.  One step -- no muss, no fuss. */
  197.  
  198.         GetClip(oldClip = NewRgn());
  199.         SetClip(rgn);
  200.         DoDrawControls(window, true);        /* Redraw content scrollbars for new activate state. */
  201.         SetClip(oldClip);
  202.         DisposeRgn(oldClip);
  203.         DisposeRgn(rgn);
  204.  
  205.         EndContent(window);
  206.     }
  207. }
  208.  
  209.  
  210.  
  211.